package com.longrise.android.byjk.plugins.vip.myintegral;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.common.datasource.remote.LoadDataManager;

/**
 * Created by callxkj on 2017/4/14.
 * 我的积分
 */

public class MyIntegralPresenter extends MyIntegralContract.Presenter {

    @Override
    protected void init() {
        toGetUserScores();
    }


    /**
     * 获取当前积分
     */
    private void toGetUserScores() {
        EntityBean bean = new EntityBean();
        bean.set("userid", UserInfor.getInstance().getUserid());
        bean.set("cardno", UserInfor.getInstance().getUsersfzh());
        EntityBean fbean = new EntityBean();
        fbean.set("bean", bean);
        mView.showLoadingDialog();
        LoadDataManager.getInstance().callService(null, UrlConstants.BaseUrl,
                "bbt_fee_sMyAccounts", fbean, new LoadDataManager.OnRequestCallListener() {

                    @Override
                    public void onSuccess(String key, String service, Object result) {
                        try {
                            EntityBean bean = (EntityBean) result;
                            Integer resultstate = bean.getInt("resultstate");
                            String resultdesc = bean.getString("resultdesc");
                            EntityBean resultBean = bean.getBean("result");
                            if (resultstate == 1) {
                                String vipscores = resultBean.getString("vipscores");
                                mView.setUserScores(vipscores);
                            } else {
                                mView.showToast(resultdesc);
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFinished(String key, String service) {
                        mView.dismissLoadingDialog();
                    }

                    @Override
                    public void onError(String key, String service, Throwable ex, boolean isOnCallback) {

                    }
                });
    }
}
